package com.sjf.day01;

import java.util.Arrays;

/**
 * 插入排序
 * @author <sjf753@qq.com>
 * @since 2021/12/6 14:49
 **/
public class insertSort {

    public static void insertsort(int[] arr){
        int n = arr.length;
        for(int i=1;i<n;i++){
            for(int j=i-1;j>=0 && arr[j]>arr[j+1];j--){
                swap(arr,j,j+1);
            }
        }
    }
    public static void swap(int[] a,int i,int j){
        a[i] = a[i] ^ a[j];
        a[j] = a[i] ^ a[j];
        a[i] = a[i] ^ a[j];
    }

    public static void main(String[] args) {
        int[] a ={7,6,5,4,3,2,1};
        insertsort(a);
        System.out.println(Arrays.toString(a));
    }
}
